// Example express application adding the parse-server module to expose Parse
// compatible API routes.

const express = require('express')
const ParseServer = require('parse-server').ParseServer
const path = require('path')
const config = require('./config').parse
const port = config.port

const api = new ParseServer(config)
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

const app = express()

// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')))

// Serve the Parse API on the /parse URL prefix
const mountPath = '/parse'
app.use(mountPath, api)

const ParseDashboard = require('parse-dashboard')

const dashboard = new ParseDashboard({
  'apps': [
    {
      'serverURL': config.serverURL,
      'appId': config.appId,
      'masterKey': config.masterKey,
      'appName': 'MyApp'
    }
  ]
})

app.use('/dashboard', dashboard)

const httpServer = require('http').createServer(app)
httpServer.listen(port, () => {
  console.log('parse-server running on port ' + port + '.')
})
